package b;

import java.util.ArrayList;
import java.util.Scanner;

// p194 任务实施
class Goods {
    private String id; // 商品型号
    private String name; // 商品名称
    private String brand; // 商品品牌
    private int count; // 商品数量
    private double price; // 商品价格

    public Goods(String id, String name, String brand, int count, double price) {
        this.id = id;
        this.name = name;
        this.brand = brand;
        this.count = count;
        this.price = price;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

public class Demo5 {
    public static void main(String[] args) {
        Demo5 task1 = new Demo5();
        ArrayList<Goods> arrList = new ArrayList<>();
        arrList.add(new Goods("A001", "洗衣机", "美的", 2, 454543.6));
        arrList.add(new Goods("A002", "洗衣机", "海尔", 3, 486783.3));
        while (true) {
            task1.homePage(); // 显示主页
            System.out.print("请选择您要使用的功能：");
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            switch (n) {
                case 1:
                    task1.addShop(arrList); // 调用商品入库功能
                    break;
                case 2:
                    task1.showShop(arrList); // 调用商品显示功能
                    break;
                case 3:
                    task1.delShop(arrList); // 调用商品出库功能
                    break;
                case 4:
                    System.out.println("欢迎使用本系统，谢谢"); // 退出库存管理系统
                    return;
                default:
                    System.out.println("输入错误");
            }
        }
    }

    // 库存管理系统首页功能
    public void homePage() {
        System.out.println("==================================================================");
        System.out.println("欢迎使用库存管理系统，请选择功能：");
        System.out.println("1.商品入库");
        System.out.println("2.商品查看");
        System.out.println("3.商品出库");
        System.out.println("4.退出");
        System.out.println("==================================================================");
    }

    // 库存管理系统商品入库功能
    public void addShop(ArrayList<Goods> arrList) {
        Scanner sc = new Scanner(System.in);
        System.out.println("商品是否要入库（Y:是，N:否）:");
        String choice = sc.next();
        if (choice.equalsIgnoreCase("y")) {
            System.out.println("请输入商品的型号：");
            String id = sc.next();
            System.out.println("请输入商品的名称：");
            String name = sc.next();
            System.out.println("请输入商品的品牌：");
            String brand = sc.next();
            System.out.println("请输入商品的数量：");
            int count = sc.nextInt();
            System.out.println("请输入商品的价格：");
            double price = sc.nextDouble();
            Goods goods = new Goods(id, name, brand, count, price);
            arrList.add(goods);
            System.out.println("商品已成功入库");
        } else {
            System.out.println("商品入库取消");
        }
    }

    public void showShop(ArrayList<Goods> arrList) {
        System.out.println("型号\t名称\t品牌\t数量\t价格\t");
        for (Goods g : arrList) {
            System.out.println(g.getId() + "\t" + g.getName() + "\t" + g.getBrand() + "\t" + g.getCount() + "\t" + g.getPrice());
        }
    }

    public void delShop(ArrayList<Goods> arrList) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入需要出库的商品型号：");
        String id = sc.next();
        boolean flag = false;
        for (int i = 0; i < arrList.size(); i++) {
            Goods g = arrList.get(i);
            if (g.getId().equals(id)) {
                arrList.remove(i);
                flag = true;
                System.out.println("商品已出库");
            }
        }
        if (!flag) {
            System.out.println("无此型号商品，商品出库失败");
        }
    }
}